package com.coolt.client.logic;

import java.util.ArrayList;
import java.util.List;

import com.coolt.client.AsyncService;
import com.coolt.client.ui.Catalogo;
import com.coolt.domain.Item;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ListarCatalogo {
	private List<Item> item;

	public List<Item> getItem() {
		return item;
	}

	public void setItem(List<Item> item) {
		this.item = item;
	}

	public ListarCatalogo() {
/*
		AsyncService.getService().listarItens(new Item(),
				new AsyncCallback<List<Item>>() {
					public void onSuccess(List<Item> result) {
						item = result;
						Catalogo.getVerticalPanel().add(getCatalogo());
					}

					public void onFailure(Throwable caught) {
						Window.alert(caught.toString());
					}
				});
				*/
	}

	public FlexTable getCatalogo() {
		
		 List<Item> item=new ArrayList<Item>();
			for(int i=0;i<9;i++){
				Item t=new Item();
				t.setImgitem("imagem/temp/filmes/"+i+".jpg");
				t.setAtores("Atores...");
				t.setAmazonURL("imagem/temp/filmes/estrelas.jpg");
				item.add(t);
			}
		
		 

		int qlinha = item.size() / 4;
		int cont = 0;
		final FlexTable catalogo = new FlexTable();
		for (int i = 0; i < qlinha; i++) {
			for (int j = 0; j < 4; j++) {

				Item t = item.get(cont);

				VerticalPanel verticalPanel = new VerticalPanel();
				Image cartaz = new Image();
				cartaz.setUrl(t.getImgitem());
				verticalPanel.add(cartaz);
				Image pontuacao = new Image();
				pontuacao.setUrl(t.getAmazonURL());
				verticalPanel.add(pontuacao);
				Label descricao = new Label(t.getNmitem());
				descricao.setStyleName("descricao");
				verticalPanel.add(descricao);
				Hyperlink mais = new Hyperlink("mais", "mais");
				verticalPanel.add(mais);
				catalogo.setWidget(i, j, verticalPanel);
				cont++;
			}
		}

		return catalogo;
	}

}
